/*
 * @Description: 生成档号弹窗
 * @Author: Rfan
 * @Date: 2022-07-14 15:21:21
 * @LastEditTime: 2022-07-14 15:28:21
 */

import { useEffect, useState } from 'react';
import { Button, Modal, Steps, Typography } from 'antd';
import type { FC } from 'react';
import { useLevelTableContext } from '@/components/LevelTable/contexts/LevelTableContext';
import StepContent from '@/components/LevelTable/componentes/optBtns/GenerateArcNo/components/StepContent';

const { Paragraph, Title, Text } = Typography;
const { Step } = Steps;

interface IGenerateArcNoDialog {
  info: any;
}

const GenerateArcNo: FC<IGenerateArcNoDialog> = (props) => {
  const { info } = props;
  const { baseInfo, selectItems, genArcNoFunc } = useLevelTableContext();

  // 弹窗展示状态
  const [visible, setVisible] = useState(false);

  const [tipsFlag, setTipsFlag] = useState(true);

  const [current, setCurrent] = useState(2);

  useEffect(() => {
    if (visible) {
      //
    }
  }, [visible]);

  const onCancel = () => {
    setVisible(false);
  };

  const generateArcNo = () => {
    const params = {
      atCode: info.atCode,
      atType: info.atType,
      commonParams: {
        dbName: info.dbName
      },
      entryIdList: selectItems,
      level: info.level
    };
    genArcNoFunc(params).then(() => {
      onCancel();
    });
  };

  return (
    <>
      <Button
        type="primary"
        onClick={() => {
          setVisible(true);
        }}
      >
        生成档号
      </Button>
      <Modal
        destroyOnClose
        title={tipsFlag ? '生成档号' : '生成档号中…'}
        visible={visible}
        width={600}
        onCancel={() => {
          onCancel();
        }}
        footer={[
          <Button
            key="back"
            onClick={() => {
              onCancel();
            }}
          >
            取消
          </Button>,
          <Button
            key="submit"
            type="primary"
            onClick={() => {
              // setTipsFlag((state) => !state);
              generateArcNo();
            }}
          >
            开始执行
          </Button>
        ]}
      >
        {tipsFlag ? (
          <>
            <Title level={5}>您已选择了 {selectItems.length} 个条目，是否执行生成档号</Title>
            <Paragraph>
              <Text>注：</Text>
              <ol>
                <li>依据档号生成规则，已选档案将按照赋予/重新赋予档案；</li>
                <li>与档号相关的其它关联字段将根据【元数据关联】进行同步处理。</li>
              </ol>
            </Paragraph>
          </>
        ) : (
          <>
            <Steps current={current}>
              <Step title="Finished" />
              <Step title="In Progress" />
              <Step title="Waiting" />
            </Steps>
            <StepContent activeSteps={current} />
          </>
        )}
      </Modal>
    </>
  );
};

export default GenerateArcNo;
